/*
 * Main.java
 *
 * Created on January 9, 2008, 9:49 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package thread;
import java.util.concurrent.*;
import java.io.*;

/**
 *
 * @author Maria Freiman
 */
class Threads {
    private Integer sum=new Integer(0);
    
    
    public static void main(String[] args) {
        Threads test=new Threads();
        System.out.println("What is sum ? " + test.sum);
      }
    public void Threads(){
        ExecutorService executor=Executors.newFixedThreadPool(1000);
        
        //Create and launch 1000 threads
        for(int i=0; i<1000; i++){
            executor.execute(new SumTask());
        
        }
        
        executor.shutdown();
        
        while(!executor.isTerminated()){
        }
    }
    //without synchronization Implement the run method in Runnable
    private class SumTask implements Runnable{
            public void run() {
            int value=sum.intValue() + 1;
            sum=new Integer(value);
   
         }
     }
 }